/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package th.stripes.util;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Locale;
import net.sourceforge.stripes.validation.TypeConverter;
import net.sourceforge.stripes.validation.ValidationError;

/**
 *
 * @author fikri
 */
public class DateConverter implements TypeConverter<Date> {

    @Override
    public void setLocale(Locale locale) {
        locale.setDefault(new Locale("ms_MY"));
    }

    @Override
    public Date convert(String string, Class<? extends Date> type, Collection<ValidationError> clctn) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
        Date date = null;
        try{
            date = sdf.parse(string);
        }catch (Exception e){
            e.printStackTrace();
        }
        return date;
    }
    
}
